package cn.tedu.crm.user.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.stp.StpUtil;
import cn.tedu.crm.base.response.JsonResult;
import cn.tedu.crm.user.pojo.dto.PasswordUpdateDTO;
import cn.tedu.crm.user.pojo.dto.PersonalUserParam;
import cn.tedu.crm.user.pojo.vo.UserVO;
import cn.tedu.crm.user.service.PersonalService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/api/sys/users/profile")
public class PersonalController {

    @Autowired
    private PersonalService personalService;

    @GetMapping("/select")
    public JsonResult userSelectById() {
        UserVO userVO = personalService.userSelectById();
        return JsonResult.success(userVO);
    }

    @PatchMapping("/password")
    @SaCheckLogin
    public JsonResult updatePassword(@Valid @RequestBody PasswordUpdateDTO dto) {
        personalService.updatePassword(dto);
        return JsonResult.success();
    }

    @PutMapping("/update")
    @SaCheckLogin
    public JsonResult updateUser(@Valid @RequestBody PersonalUserParam personalUserParam) {
        personalService.updateUser(personalUserParam);
        return JsonResult.success();
    }

    @PatchMapping("/avatar")
    @SaCheckLogin
    public JsonResult updateAvatAr(@RequestParam String avatar) {
        log.debug("控制层{}"+avatar);
        personalService.updateAvatar(avatar);
        return JsonResult.success();
    }
}
